#ifdef CONFIG_EULEROS_SWAPMM_TLB
#include <linux/mm.h>
#include <linux/page-flags.h>
static bool swapmm_hotreplace __read_mostly;
static int __init swapmm_hotreplace_env(char *str)
{
	if (strtobool(str, &swapmm_hotreplace) != 0) {
		pr_info("swapmm_pagetable_reuse usage:
			swapmm_pagetable_reuse=[0|1]\n");
		return -EINVAL;
	}

	return 0;
}
early_param("swapmm_pagetable_reuse", swapmm_hotreplace_env);

bool swapmm_hotreplace_enabled(void)
{
	return swapmm_hotreplace;
}
EXPORT_SYMBOL(swapmm_hotreplace_enabled);
/**
 * mem_mirror_soft_offline_page - Exported version of soft_offline_page
 * Should only used for memory mirror in swapmm module
 */
int mem_mirror_soft_offline_page(struct page *page, int flags)
{
	int ret;

	ret = soft_offline_page(page_to_pfn(page), flags);
	/*
	 * It means the page can be offlined but failed to be migrated,
	 * return EAGAIN instead of EBUSY.
	 */
	if (ret == -EBUSY && (PageLRU(page) || __PageMovable(page)))
		return -EAGAIN;

	/*
	 * We only deal with cases when the whole process succeed while the HWPoison
	 * flag has not been set.
	 * It is caused by the racing between migration and page fault, where the
	 * migration process fails to put page back to buddy allocator because of
	 * the increase of page count by the fault process.
	 * If the page count turns 0, we can add the flag here, otherwise return.
	 */
	if (ret != 0 || PageHWPoison(page))
		return ret;
	if (page_ref_count(page) == 0 && page_handle_poison(page, PageHuge(page), false))
		return ret;
	return -EAGAIN;
}
EXPORT_SYMBOL(mem_mirror_soft_offline_page);
#endif /* CONFIG_EULEROS_SWAPMM_TLB */
